import { defineStore } from "pinia";
import { AccountType, UserInfoType } from "../types/user";
import { userLogin } from "../api/user";
import router from "../router";
type AccountStateType = {
  userInfo: UserInfoType | null;
};
export const useAccount = defineStore("user", {
  state: (): AccountStateType => {
    return {
      userInfo: null,
    };
  },
  actions: {
    async userLoginAction(account: AccountType) {
      let res = await userLogin(account);
      console.log(res);
      this.userInfo = res.data;
      //路由方法
      router.go(-1);
      // router.push("/mine");
    },
  },
  persist: {
    key: "userInfo-2303",
  },
});
